package com.example.springstudy.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zhaojunzhou
 * @date 2020/4/12 10:35
 * @ControllerAdvice 执行的所有controller会被这个切面所包含，即所有的controller
 *                      都会经过这个切面
 */
@ControllerAdvice
public class GlobleExceptionHandler  {
    /**
     * 定义切面的处理规则,所有的报错都会经行这个处理器
     * @param e 捕获的异常
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public String doErro(HttpServletResponse response, HttpServletRequest httpServletRequest,Exception e) {

        return "erro";
    }
}
